import axios from 'axios'
import { ApiError } from './error'

export const caller = axios.create({
    baseURL: 'https://api.weixin.qq.com',
    responseType: 'json',
})

caller.interceptors.response.use((resp) => {
    if (resp.config.responseType === 'json' && typeof resp.data === 'object' && resp.data) {
        if (resp.data.errcode) {
            throw new ApiError(resp.data)
        }
    }
    return resp
})
